<?php
namespace app\index\model;
use think\Model;
use think\Db; 
use think\Request;

class PhoneNum extends Model
{
	public function setPhone($phone,$num){
		self::where('time','<',date('Y-m-d H:i:s',time()-180))->delete();
		$data = self::where('phone',$phone)
				->where('time','<=',date('Y-m-d H:i:s',time()))
				->where('time','>=',date('Y-m-d H:i:s',time()-5))->find();
		if (!$data) self::insert([
			'phone' => $phone,
			'num' => $num,
			'time' => date('Y-m-d H:i:s'),
		]);
	}

	public function getLastOne($phone){
		return self::where('phone',$phone)->order('time desc')->find();
	}
}